import 'dart:convert';

import 'package:example/generated/json/base/json_convert_content.dart';
import 'package:example/viewmodel/second_viewmodel.dart';
import 'package:flutter_scaffold/flutter_scaffold.dart';

class ResponseDataEntity<T> {
  T? data;
  int errorCode = 0;
  String? errorMSg;

  ResponseDataEntity();

  factory ResponseDataEntity.fromJson(Map<String, dynamic> json) {
    T? data = JsonConvert.fromJsonAsT<T>(json['data']);
    if (data == null) {
      Log.i("json数据转为${T}实体为null,请核实数据:\n${json['data']}");
    }
    return ResponseDataEntity<T>()
      ..errorCode = json['errorCode']
      ..errorMSg = json['errorMsg']
      ..data = data;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['errorCode'] = errorCode;
    data['errorMSg'] = errorMSg;
    data['data'] = jsonEncode(data);
    return data;
  }
}
